arcade-panel: degunk variable names
[clinton/3d-models.git] / ble arcade controller / arcade-box.scad
1 // arcade controller thing
2 // Copyright (c) 2017 Clinton Ebadi <clinton@unknownlamer.org>
3 // GPLv3 or (at your option) any later version
4 // .. insert license text here ...
5
6 // todo:
7 // - hinge
8 // - screw holes + captive nut to mount
9 // - internal mount for mcu and battery
10 // - hole for usb panel mount
11 // - bevel lid
12
13 // maybe/wishlist:
14 // - wire routing clips on panel?
15 // - buttons on side for pinball?
16 // - vent under mcu/battery?
17 // - slant panel toward player?
18
19 // bugs:
20 // - hinge is not aligned -- either male arm length or connector placement is wrong
21
22 use <obiscad/bcube.scad>
23 use <obiscad/attach.scad>
24 use <joints.scad>
25
26 // PREVIEW
27 preview();
28
29 module preview () {
30 rotate ([-10, 0, 0]) translate ([0, 0, box_depth+20]) panel ();
31 case ();
32 for (i = [2 ,4]) translate ([panel_width+hinge_joint_width*i, 0, 0]) hinge_male ();
33
34 }
35
36 // CONFIGURATION
37
38 panel_width = 250;
39 panel_height = 130;
40
41 box_depth = 80;
42 box_wall = 2;
43 box_base_thickness = 5;
44
45 $button_d = 30; // I think this should be special
46
47 joystick_width = 85;
48 joystick_height = 40;
49
50 // fixme: these are a bit confused
51 hinge_joint_width = 8;
52 hinge_joint_thickness = 5;
53 hinge_box_base_thicknesseight = 10;
54 hinge_joint_height = 10;
55 hinge_arm_length = 50;
56
57
58 // gunk that should be elsewhere...
59 // bcube parameters, clean up
60 cr = box_wall*2;
61 cres = 0;
62
63 // PANEL COMPONENTS
64
65 module button (bezel = $button_d+4) {
66 circle (d=$button_d);
67 %circle(d=bezel);
68 }
69
70 module joystick () {
71 bolt_d = 8;
72 center_hole_d = 24;
73
74 for (x = [-joystick_width/2, joystick_width/2], y = [-joystick_height/2, joystick_height/2]) {
75 translate ([x, y, 0]) circle (d=bolt_d); // need slot instead
76 }
77 circle (d=center_hole_d);
78 %square ([joystick_width, joystick_height], center=true); // not right...
79 }
80
81
82 // CASE
83
84 module case_base (h=box_base_thickness) {
85 bcube([panel_width, panel_height, h], cr, cres);
86 }
87
88 module case_walls () {
89 difference () {
90 union () {
91 difference() {
92 bcube([panel_width, panel_height, box_depth-box_base_thickness], cr, cres);
93 bcube([panel_width-box_wall*2, panel_height-box_wall*2, box_depth+1], cr, cres);
94 }
95 attach (case_connector_wall (x=10), hinge_connector_back ()) hinge_female_base ();
96 }
97 attach (case_connector_wall (x=10), hinge_connector_back ()) hinge_female_cut ();
98 }
99 %connector (case_connector_wall (x=10));
100 }
101
102 module case () {
103 case_base ();
104 translate ([0, 0, box_depth/2]) case_walls ();
105 }
106
107
108 // todo:
109 // specify which wall (rear, front, left, right). vector addition may help...
110 // offset from center of wall, as vector (and use vector subtraction!)
111 // optional: inside/outside
112 function case_connector_wall (x=0, y=0, z=0) = [ [panel_width/2-x, panel_height/2-y, (box_depth-box_base_thickness)/2-z], [0,-1, 0], 0 ];
113
114 // HINGE
115
116 // hinge todo:
117 // calculate z offset so that hinge will align when closed
118 // calculate offset into panel surface for length of peg
119 // attach to case, calculating offset from wall as fixed value + width
120
121 // add connector for pin to socket so that can easily be test fit in
122 // software instead of guessing
123
124 // should panel connector be on its side? Limits motion to 90⁰ Or
125 // maybe just walls only + fillet with no base...
126
127 function hinge_connector_back (th=hinge_joint_thickness*2, h=hinge_box_base_thicknesseight) = [ [0, th/2, h/2], [0,1, 0], 0 ];
128
129 // todo:
130 // gusset support underneath
131 // split into base and negative so that a hole can be punched into case wall
132
133 module hinge_female_base () {
134 w = hinge_joint_width * 2;
135 th = hinge_joint_thickness * 2;
136
137 %connector (hinge_connector_back ());
138 cube ([w, th, hinge_box_base_thicknesseight], center=true);
139 }
140
141 module hinge_female_cut () {
142 w = hinge_joint_width * 2;
143 th = hinge_joint_thickness * 2;
144
145 // cruft from earlier hacking, remove...
146 jt = hinge_joint_thickness;
147 jw = hinge_joint_width;
148
149 joint_male_negative(male_joint_width=jw, male_joint_thickness=jt, forward_rom=90, backward_rom=90, male_joint_height=hinge_joint_height);
150 }
151
152 module hinge_female () {
153 difference () {
154 hinge_female_base ();
155 hinge_female_cut ();
156 }
157 }
158
159 module hinge_male () {
160 for (i=[0,1]) mirror ([0, i, 0]) translate ([0, -hinge_arm_length/4, 0])
161 joint_male(male_joint_width=hinge_joint_width, male_joint_thickness=hinge_joint_thickness, male_joint_height=hinge_arm_length/2, side=true);
162
163 }
164
165
166 // hinge to panel...
167 // mount hinge on panel arm_length back from edge
168
169 // fixme: wall thickness is not taken into account
170
171 // PANEL
172
173
174 // cleanup after general case_connector_wall() is done
175 panel_c = [ [panel_width/2-10, panel_height/2-hinge_arm_length, -box_base_thickness/2+0.01], [0,0, 1], 180 ];
176
177 module panel () {
178 difference () {
179 case_base ();
180 linear_extrude (box_base_thickness*2,center=true) panel_layout ();
181 }
182 %connector (panel_c);
183 attach (panel_c, hinge_connector_back ()) hinge_female ();
184 }
185
186 module panel_attach (position, angle=0) {
187 x = position[0];
188 y = position[1];
189 c1 = [ [x, y, box_base_thickness/2], [0,0,1], angle ];
190 a1 = [ [0,0, 0], [0,0,0], 0 ];
191 // %connector (c1); // fixme: don't use 2d for layout
192 attach (c1, a1) children ();
193 }
194
195 // panel layout inspired by the Neo Geo layout
196 module panel_layout () {
197 translate ([-panel_width/2 + 40, 0, 0]) {
198 panel_attach ([0, 0], 90) joystick ();
199
200 // p1, coin (floating off in the distance...)
201 translate ([140, 0, 0]) {
202 $button_d=16;
203 for (x = [0, $button_d+10]) {
204 panel_attach ([x, 42]) button ();
205 }
206 }
207
208 // a, b, c, d
209 translate ([60, -20, 0]) {
210 panel_attach ([0, 0]) button ();
211 for (i = [ 1 : 3 ]) {
212 panel_attach ([i*($button_d+10)-10, $button_d]) button ();
213 }
214 }
215 }
216 }